<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <link href="style3.css" rel="stylesheet" type="text/css" />
    </head>
    <style type="text/css">
        #Status     {margin-left:0px; top: 240px; width: 100px; height:0px; position: inherit}
        #SetPerPage {margin-left: 250px; top: 0px; width: 150px; height:15px; position: relative}
        #JumpToPage {margin-left: 500px; top: -28px; width: 150px; height:15px; position: relative}

        #Previous               {margin-left: 250px; top: 300px; width: 150px; height:15px; position: inherit}
        #PreviousInactive       {margin-left: 250px; top: 300px; width: 150px; height:15px; position: inherit}
        #Next                   {margin-left: 500px; top: 28px; width: 150px; height:15px; position: relative}
        #NextInactive           {margin-left: 500px; top: 28px; width: 150px; height:15px; position: relative}

    </style>
</html>
<?php
//Connect to database
$conn = mysql_connect( "localhost", "root", "" ) or die( mysql_error() );
mysql_select_db( "mydb", $conn ) or die( mysql_error() );

//Intiating per page to 5 conferences per page
if ( $_GET[ 'pp' ] > 0 || $_GET[ 'pp' ] == Null ) {
$pp = ( isset( $_GET[ 'pp' ] ) ) ? (int) $_GET[ pp ] : 5;
} else {
    echo '<script type="text/javascript">', 'alert("Error: You can not set the view per page to this value!")', '</script>';
    $pp = 5;
}

//Calculating the total number of pages needed to view the information
$result = mysql_query( "SELECT conference_id FROM conference" ) Or die( mysql_error() );
$users_nm    = mysql_num_rows( $result );
$total_pages = (int) ceil( $users_nm / $pp );

//Intiating the initial page and handling inputs exceptions
if ( $_GET[ 'p' ] <= $total_pages && $_GET[ 'p' ] > 0 || $_GET[ 'p' ] == Null ) {
    $p = ( isset( $_GET[ 'p' ] ) ) ? (int) $_GET[ p ] : 1;
} else {
    if ( $_GET[ 'p' ] <= 0 && $_GET[ 'p' ] != null ) {
        $p = 1;
        echo '<script type="text/javascript">', 'alert("Error: You Can Not Jump to the Specified Page")', '</script>';
    } else {
        $p = $total_pages;
        echo '<script type="text/javascript">', 'alert("Error: You Can Not Jump to the Specified Page")', '</script>';
    }
}
$start = (int) ( $p - 1 ) * $pp;
$result = mysql_query( "SELECT conference_id, long_name FROM conference LIMIT $start, $pp" ) Or die( mysql_error() );
echo '<table width="100%">
<tr>
<td><b>Conference</b>
</td>
</tr>';
while ( $row = mysql_fetch_assoc( $result ) ) {
    echo "<tr>
<td>{$row['long_name']}</td>
<td><a href='conferencePage.php?conference_id={$row['conference_id']}'>Go To Conference</a </td>
</tr>";
}
echo '</table>';
if ( $total_pages > 1 && $p <= $total_pages ) {
    for ( $x = 1; $x <= $total_pages && $x <= 6; $x++ ) {
        echo '<a href="?p=' . $x . '&pp=' . $pp . '">' . $x . '</a> ';
    }
}
?>
<html>
    <head>
        <link href="style3.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <div id="Status">
            <form action= 'ViewConferencesPerPage.php' method="GET" name="SetPerPage" enctype="multipart/form-data">
                <p><strong>You are currently viewing page <?PHP echo $p ?> of <?PHP echo $total_pages ?> and viewing <?PHP echo $pp ?> conference(s) per page</strong></p>
            </form>
        </div>
        <div id="SetPerPage">
            <form action= 'ViewConferencesPerPage.php' method="GET" name="SetPerPage" enctype="multipart/form-data">
                <p>Display#:
                    <input name="pp" value="<?PHP print $pp; ?>"size="5" maxlength="100">
                </p>
                <p>
                    <input name="Set" type="submit" value="Set">
                </p>
            </form>
        </div>
        <div id="JumpToPage">
            <form action= 'ViewConferencesPerPage.php' method="GET" name="JumpToPage" enctype="multipart/form-data">
                <p>Jump to page:
                    <input name="p" value="<?PHP print $p; ?>" size="5" maxlength="100">
                </p>
                <p>
                    <input name="Go" type="submit" value="Go">
                </p>
                <input name="pp" type="hidden"  value="<?php echo $pp; ?>">
            </form>
        </div>
        <?php if ( $p < $total_pages ):?>
        <div id="Next">
            <form action= 'ViewConferencesPerPage.php' method="GET" name="Next" enctype="multipart/form-data">
                <p>
                    <input name="Next" type="submit" value="Next Page">
                </p>
                <input name="pp" type="hidden"  value="<?php echo $pp;?>">
                <input name="p" type="hidden"  value="<?php echo $p + 1;?>">
            </form>
        </div>
        <?php else:?>
        <div id="NextInactive">
            <form action= 'ViewConferencesPerPage.php' method="GET" name="NextInactive" enctype="multipart/form-data" disabled="disabled">
                <p>
                    <input name="NextInactive" type="submit" value="Next Page" disabled="disabled">
                </p>
                <input name="pp" type="hidden"  value=" <?php echo $pp;?> ">
                <input name="p" type="hidden"  value=" <?php echo $p + 1; ?>">
                <?php endif; ?>
           </form>
        </div>

        <?php if ( $p == 1 ):?>
        <div id="PreviousInactive">
            <form action= 'ViewConferencesPerPage.php' method="GET" name="PreviousInactive" enctype="multipart/form-data" disabled="disabled">
                <p>
                    <input name="PreviousInactive" type="submit" value="Previous Page" disabled="disabled">
                </p>
                <input name="pp" type="hidden"  value="<?php echo $pp; ?>">
                <input name="p" type="hidden"  value="<?php echo $p - 1; ?>">
            </form>
        </div>
    </body>
</html>
<?php else: ?>
<div id="Previous">
    <form action= 'ViewConferencesPerPage.php' method="GET" name="ViewConferences" enctype="multipart/form-data">
        <p>
            <input name="Next" type="submit" value="Previous Page">
        </p>
        <input name="pp" type="hidden"  value="<?php echo $pp; ?>">
        <input name="p" type="hidden"  value="<?php echo $p - 1; ?>">
    </form>
</div>
<?php endif; ?>
</body>
</html>